package com.heima.list;

import com.heima.array.Student;

import java.util.ArrayList;

public class ListWalk01 {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();

        list.add("123");
        list.add("sid");
        list.add("mix");

        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();

        //创建集合对象(泛型:Student)
        ArrayList<Student> stuList = new ArrayList<>();
        //创建学生数组并赋值
        Student[] stuArr = new Student[3];
        stuArr[0] = new Student("张三1",22);
        stuArr[1] = new Student("张三2",14);
        stuArr[2] = new Student("张三1",8);
        //遍历
        for (int i = 0; i < stuArr.length; i++) {//遍历空的集合
            stuList.add(i,stuArr[i]);//添加学生到集合
            System.out.println(stuList.get(i).getAge());//遍历打印集合中对象的元素值
        }
    }

}
